import javax.jms.*;
import javax.naming.Context; 
import javax.naming.InitialContext; 
import java.util.Scanner;


public class ProducerAlice {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ProducerAlice p = new ProducerAlice();
		Scanner in = new Scanner(System.in);
		
		String c;
		do
		{
			System.out.println("Enter message:");
			c = in.nextLine();
			System.out.println("Sending: " + c);
			if (c != "") p.raise(c);			
		} while (c != "");	
	}
	
	public void raise(String m)
	{
		try
		{
			Context ctx = new InitialContext();
			TopicConnectionFactory topicfactory = (TopicConnectionFactory)ctx.lookup("TopicConnectionFactory");
			Topic topic = (Topic)ctx.lookup("Messages");
			TopicConnection topicConn = topicfactory.createTopicConnection();
			TopicSession topicSess = topicConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
			
			TopicPublisher topicPub = topicSess.createPublisher(topic);
			TextMessage msg = topicSess.createTextMessage(m);
			msg.setStringProperty("sender", "Alice");
			topicPub.publish(msg);
			// TODO: Lookup the TopicConnectionFactory
			// TODO: Lookup the Topic
			// TODO: Create a new Topic Connection
			// TODO: Start a new Topic Session
			// TODO: Create the publisher
			// TODO: Create a message
			// TODO: Set the text of the message
			// TODO: Send the message
			// TODO: Close the topic connection			
		}
		catch (Exception e)
		{		
			System.out.println("Exception:" + e.getMessage());
			e.printStackTrace();			
		}		
	}	

}
